package com.edu.controller;

import com.edu.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/*
 * @Author:princess
 * @Date 2023/11/13 11 13 19:56
 *
 */
@Controller
public class TestController {
    //前端传递的参数 就是 标量型，直接使用 和 参数的 name属性 一样的形参 来接收即可
    @RequestMapping("/test01")
    public String test01(String username, Integer age, Date birth){
        System.out.println(username);
        System.out.println(age);
        System.out.println(birth);
        return "index.jsp";
    }

    @RequestMapping("/test02")
    public String test02(@RequestParam(value = "username",required = true,defaultValue = "张三") String username){
        System.out.println(username);
        return "index.jsp";
    }

    //前端传递的参数 是一个POJO对象
    @RequestMapping("/test03")
    public String test03(User user){
        System.out.println(user);
        return "index.jsp";
    }

    @RequestMapping("/test04")
    public String test04(User user,@RequestParam(value = "pageNum",defaultValue = "1") int pageNum,@RequestParam(value = "pageNum",defaultValue = "5") int pageSize){
        System.out.println(user);
        return "index.jsp";
    }

    //前端传递的参数 是一个数组或者集合
    @RequestMapping("/test05")
    public String test05(@RequestParam List<String> hobbies){
        for (String hobby : hobbies) {
            System.out.println(hobby);
        }
        return "index.jsp";
    }

    //前端传递的参数 是一个map集合
    @RequestMapping("/test06")
    public String test06(@RequestParam Map<String,Object> obj){
        System.out.println(obj.get("father"));
        System.out.println(obj.get("mother"));
        return "index.jsp";
    }

    //获取请求头的数据
    @RequestMapping("/test07")
    public String test07(@RequestHeader("user-agent") String userAgent){
        System.out.println(userAgent);
        return "index.jsp";
    }

    //获取cookie的数据
    @RequestMapping("/test08")
    public String test08(@CookieValue("JSESSIONID") String sessionId){
        System.out.println(sessionId);
        return "index.jsp";
    }

}
